const sass = require('sass');
const loadGruntTasks = require("load-grunt-tasks")
module.exports = (grunt) => {

  loadGruntTasks(grunt);
  grunt.initConfig({
    meta: {
      basePath: '../',
      srcPath: 'src/aassets/styles',  // 源码
      deployPath: 'dist/'  // 编译输出
    },
    clean: {
      temp: "dist",
    },
    sass: {
      options: {
        sourceMap: true, //是否输出sourceMap调试
        implementation: sass //依赖模块
      },
      main: {
        files: {
          // 输出路径:原路径
          'dist/css/main.css': 'src/assets/styles/main.scss'
        }
      }
    },
    cssmin: {
      target: {
        files: [{
          expand: true,
          cwd: 'dist//css',
          src: ['*.css', '!*.min.css'],
          dest: 'dist/css',
          ext: '.min.css'
        }]
      }
    },
    babel: {
      options: {
        sourceMap: true,
        presets: ["@babel/preset-env"], //转换最新特性
      },
      main: {
        files: {
          "dist/js/app.js": "src/assets/scripts/*.js",
        },
      },
    },
    uglify: {
      my_target: {
        files: [{
          expand: true,
          cwd: 'dist/js',
          src: '**/*.js',
          dest: 'dist/js'
        }]
      }
    },
    htmlmin: {
      dist: {
        options: {
          removeComments: true,
          collapseWhitespace: true
        },
        files: {
          'dist/index.html': 'src/index.html',
          'dist/about.html': 'src/about.html'
        }
      },
      dev: {
        files: [{
          expand: true,
          cwd: 'app',
          src: ['src/**/*.html', '*.html'],
          dest: 'dist'
        }]
      }
    },
    watch: {
      js: {
        files: ["src/**/*.js"],
        tasks: ["babel"],
      },
      css: {
        files: ["src/**/*.scss"],
        tasks: ["sass"],
      },
    }
  });
  //   组合命令
  grunt.registerTask("default", ["clean", "sass", 'cssmin', "babel", "uglify", 'htmlmin', "watch"]);
};